// 定义🐍的身体
export default class SnakeBody {
    // 是不是蛇头
    private isHead: boolean;
    // 单个身体的移动方向

    // 初始化身体对应的dom元素
    constructor(isHead: boolean = false, private bodyEle: HTMLElement) {
        this.isHead = isHead;
    }

    // 获取🐍的坐标
    get leftX() {
        return this.bodyEle.offsetLeft;
    }
    get topY() {
        return this.bodyEle.offsetTop;
    }
    get position(): [number, number] {
        return [this.leftX, this.topY];
    }

    // 设置🐍的坐标
    set leftX(value: number) {
        this.bodyEle.style.left = value + 'px';
    }
    set topY(value: number) {
        this.bodyEle.style.top = value + 'px';
    }
    set position([leftX,topY]) {
        this.leftX=leftX;
        this.topY=topY;
    }

    // 🐍开始移动
    Run({leftX,topY}:{leftX:number,topY:number}):void{
        this.position=[leftX,topY];
    }

    // 删除dom元素
    removeBody(){
        this.bodyEle.remove();
    }
}